define [
  'chaplin'
  'views/base/form_view'
  'views/base/file_view'
  'text!templates/movimento/form.html'
  'collections/user_collection'
  'lib/enums'
  'lib/number_utils'
], (Chaplin, BaseFormView, FileView, Template, UserCollection, Enums, NumberUtils) ->

  'use strict'

  class MovimentoFormView extends BaseFormView

    # Override Attributes
    # =============================================================

    template: Template

    validationRules :
      operacao    :
        required  : true
      valor    :
        required  : true


    validatorSettings: ignore: ''

    # events:
    #   "change [name='alterarArquivos']" : "alterarArquivosChangeHandler"

    # Override Methods
    # =============================================================

    afterRender: ->
      super
      @setupMasks()

    setupMasks: ->
      @DOMElements.$valor              .setMask 'decimal'

    cacheDOMElements: ->
      _.extend super,
        $operacao         : @$ '[name="operacao"]'
        $observacao       : @$ '[name="observacao"]'
        $valor            : @$ '[name="valor"]'

    getTemplateData: ->
      _.extend super,
        tipoOperacao : Enums.tipoOperacao

    fillForm: ->
      @DOMElements.$operacao.val          @model.get 'operacao'
      @DOMElements.$observacao.val        @model.get 'observacao'
      @DOMElements.$valor.val             @setDecimal(@model.get('valor'))

    fillModel: ->
      @model.set
        operacao          : @DOMElements.$operacao         .val()
        observacao        : @DOMElements.$observacao       .val()
        valor             : @fixDecimal(@DOMElements.$valor.val())

    saveData: ->
      super
       # @publishEvent 'feedback:error', 'upload.sem.arquivos'

    setDecimal: (val) ->
      if val
        return NumberUtils.number_format(val, 2, ',', '.')
      else
        return '0,00'

    fixDecimal: (val='') ->
      return val.replace(/\./g, '').replace ',', '.'
